home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 20 / Cream of the Crop 20 (Terry Blount) (1996).iso / program / n_b_v203.zip / MENU-IDX.DMO < prev    next >
Text File  |  1996-07-04  |  8KB  |  187 lines

  1. $if 0
  2.     ┌──────────────────────────╖                        PowerBASIC v3.20
  3.  ┌──┤          DASoft          ╟──────────────────────┬──────────────────╖
  4.  │  ├──────────────────────────╢    Copyright 1995    │ DATE: 1995-10-01 ╟─╖
  5.  │  │ FILE NAME   MENU-IDX.DMO ║          by          ╘════════════════─ ║ ║
  6.  │  │                          ║  Don Schullian, Jr.                     ║ ║
  7.  │  ╘══════════════════════════╝                                         ║ ║
  8.  │ A license is hereby granted to the holder to use this source code in  ║ ║
  9.  │ any program, commercial or otherwise,  without receiving the express  ║ ║
  10.  │ permission of the copyright holder and without paying any royalties,  ║ ║
  11.  │ as long as this code is not distributed in any compilable format.     ║ ║
  12.  │  IE: source code files, PowerBASIC Unit files, and printed listings   ║ ║
  13.  ╘═╤═════════════════════════════════════════════════════════════════════╝ ║
  14.    │                ....................................                   ║
  15.    ╘═══════════════════════════════════════════════════════════════════════╝
  16.  
  17.   This menu is primarily designed to provide the user a quick and efficient
  18.   method of searching long lists of items that are in alphabetical order.
  19.   Index lists and the like lend themselves very well here as it usually
  20.   only takes 3 or 4 key-strokes to get to the exact entry being sought.
  21.  
  22.   A secondary ability of the function is to be able to "tag" items or groups
  23.   of items. This is done by placing a special character at the end of the
  24.   elements that have been tagged.
  25.  
  26.   I have used both of these styles for years now in a program that handles
  27.   over 8,000 names and 20,000 products and it still only requires an average
  28.   of 4 keys to find a particular item. The tagging feature allows the user
  29.   to select only a few items to print, preform tasks on, etc. and makes a
  30.   program very friendly and very powerful.
  31.  
  32.   Unlike the other two Tmenu FUNCTIONS, this one uses a stationary bar and
  33.   moves the entire list up and down. This makes it easier for the user to
  34.   maintain eye contact while typing in the search pattern. It also allows
  35.   display of items both preceding and following the "center" item which,
  36.   in turn, allows the user to quickly scan the whole area. Assuming we
  37.   were looking for a "SMITH, JOHN T.". There may be several "SMITH"'s and
  38.   maybe even a couple "SMITH, JOHN"'s but by typing in "SMITH" the user
  39.   very quickly sees all the Smith's and can then use the arrow keys to
  40.   move to the exact one.
  41.  
  42.   There are a few differences here from fTmenuHOT% that are required to
  43.   make this menu work correctly. Please review the list below:
  44.     I$(0) holds the data for TmenuTYPE + "Menu Title"
  45.     I$(1) and on is sorted and in UPPER CASE
  46.           the items should NOT be padded with spaces but it will still work
  47.     Any NULL items in the array follow the sorted items
  48.     The right-most character of the tagged items is CHR$(.HKs)
  49.     IF H$ <> "" THEN fHelpLine$ is used to save/restore the screen
  50.     .Irows must be an odd number
  51.     .Icols must = 1
  52.     .Iwide must be set to the correct length of the longest item not
  53.            counting the tagging character
  54.            or
  55.            the length of I$(1) will be used
  56.  
  57.   Several keys (below) are common to both type menus while others only
  58.   kick-in when "tagging" is in effect. The <ENTER> key switches operations
  59.   depending on the usage.
  60.   Note how <F-9> operates: unlike fTmenuHOT% where it turns everything ON
  61.   here it only works on whatever the search string matches:
  62.     eg: "SMITH" is being searched for when <F-9> is pressed
  63.              all items starting with "SMITH" will be tagged
  64.     eg: the search string is NULL but "SMITH, JOHN T." is the hot item
  65.              all items starting with "S" will be tagged.
  66.  
  67.     <UP><DOWN>    move 1 position in the list    <─┐
  68.     <PgUp><PgDn>  move .Irows - 1 in the list    <─┤ removes search string
  69.     <HOME><END>   move to first/last in the list <─┘
  70.     <RIGHT><LEFT> add/decrease search string
  71.     <BkSp>        same as <LEFT>
  72.     <DEL>         erase search string
  73.     <LETTER>      add this letter to the search pattern/move to 1st match
  74.     <ENTER>       if NOT tagging: select item/exit menu
  75.     ───────────── IF TAGGING ──────────────────────────────────────────────
  76.     <ENTER>       toggle item ON/OFF note: <SPACE> may be in the index items
  77.     <F-10>        exit menu
  78.     <F-4>         un-tag all items
  79.     <F-9>         tag all items matching current search OR
  80.                   all items starting with same 1st letter of current item
  81. $endif
  82.  
  83. $STACK 4096
  84. $STRING 32
  85. $ERROR ALL ON
  86.  
  87. RANDOMIZE 1234
  88. $INCLUDE "DAS-NB01.INC"
  89. $INCLUDE "DAS-NB02.INC"
  90. $INCLUDE "DAS-NBT1.INC"
  91. $INCLUDE "DAS-NBT3.INC"
  92.  
  93. LastItem%     = 100              ' => 50 please
  94. ScrnBackGrnd? = 112
  95. ExetKey$      = CHR$(027,0)      ' <ESC> exits
  96.  
  97. DIM tM AS TmenuTYPE
  98.   tM.Setup =   0            ' let it compute the menu position, etc
  99.   tM.Row   =   0            ' 1st row    ( will center if 0 )
  100.   tM.Col   =   0            ' 1st column ( will center if 0 )
  101.   tM.IWide =  20            ' width of items
  102.   tM.IRows =  11            ' N° of items down  ( 9 and 11 are best )
  103.   tM.ICols =   1            ' always 1
  104.   tM.Vert  =   1            ' always 1
  105.   tM.Wrap  =   0            ' NOT USED (always ZERO)
  106.   tM.HKs   =   4            ' > 0 = Tag
  107.  
  108.   tM.AttrN = 023            ' Normal Item                   : White/Blue
  109.   tM.AttrL = 116            ' Search string                 : Red/White
  110.   tM.AttrB = 113            ' Selection Bar                 : Blue/White
  111.   tM.AttrO =   0            ' NOT USED
  112.  
  113.   tM.Srow  =   1            ' turn on TsliderV
  114.   tM.Scol  =   0            ' computed
  115.   tM.Srows =   0            ' computed
  116.   tM.Aattr =  30            ' HiYellow/Blue
  117.  
  118.   tM.BrDr  =   1            ' Box Border (0 = no border) SEE: TBoxDRAW
  119.   tM.Battr = 023            ' Box Color Attribute           : White/Blue
  120.   tM.Shdo  =   1            ' Shadow type                SEE: DrawShadow
  121.   tM.Sattr = 008            ' Shadow Color Attribute        : Grey/Black
  122.   tM.Tpos  =   4            ' Title Position             SEE: MakeTbox
  123.  
  124. DIM I$(LastItem%)
  125. I$(0) = tM + "INDEX MENU"
  126.  
  127. RESTORE MENUSSdata
  128.  
  129. FOR I% = 1 TO LastItem%
  130.   READ I$ : IF I$ = "XXENDXX" THEN EXIT FOR
  131.   I$(I%) = I$
  132. NEXT
  133.  
  134. FOR I% = I% TO LastItem%
  135.   L%     = fRND%( 12, tM.Iwide )   ' variable lengths
  136.   I$(I%) = fRNDstr$( 65, 90, L% )  ' random strings
  137. NEXT
  138.  
  139. MENUSSdata:
  140. DATA "POWER BASIC"   , "AARDVARK"      , "AARONINSKY, ART"
  141. DATA "SMITH, JOHN A.", "SMITH, JOHN B.", "SMITH, JOHN C."
  142. DATA "SMITH, JOHN D.", "SMITH, JOHN E.", "SMITH, JOHN F."
  143. DATA "XXENDXX"
  144.  
  145. ARRAY SORT I$(1) FOR LastItem%
  146.  
  147. IF tM.HKs = 0 THEN
  148.     H$ = "<.ENTER/> = SELECT    <.TYPE TO SEARCH/>"
  149.   ELSE
  150.     H$ = "<.ENTER/> = TAG  <.F-4/> = ALL OFF  <.F-9/> = SEARCH ON  <.F-10/> = EXIT"
  151. END IF
  152.  
  153. HelpLineSETUP 25, 1, 80, 47
  154.  
  155. DO
  156.   TBoxFILL 1, 1, 25, 80, 177, ScrnBackGrnd?
  157.   Sn% = fTmenuINDEX% ( I$(), LastItem%, H$, ExetKey$, Sn% )
  158.   IF Sn% < 0 THEN EXIT LOOP
  159.   IF tM.HKs = 0 THEN
  160.       M$ = USING$( " YOU SELECTED N°  ### : " + I$(Sn%) + " ", Sn% )
  161.       Col? = fCenterPOS%( 1, 80, LEN( M$ ) ) + 3
  162.       Tprint 13, Col?, M$, 15
  163.     ELSE
  164.       Row? = 1
  165.       Cols? = tM.Iwide + 1
  166.       FOR X% = 1 TO LastItem%
  167.         IF fASCIIr%( I$(X%) ) <> tM.HKs THEN ITERATE
  168.         TprintCLEAR Row?, 1, Cols?, EXTRACT$( I$(X%), CHR$(tM.HKs) ), 112
  169.         INCR Row?, 1
  170.         IF Row? = 25 AND X% < ( LastItem% - 1 ) THEN
  171.           Tprint Row?, 1, " AND OTHERS... ", 112
  172.           EXIT FOR
  173.         END IF
  174.       NEXT
  175.   END IF
  176.   DELAY 2
  177. LOOP
  178.  
  179. ' ────────────────────────────────────────────────────────────────────────────
  180.  
  181. FUNCTION fGetKey% () LOCAL PUBLIC '┌────────────────────────────────────
  182.                                   '│centralize all incoming key presses
  183.   WHILE NOT INSTAT : WEND         '│rem this line out if used with EVENTs
  184.   FUNCTION = CVI(INKEY$+CHR$(0))  '│read next key press
  185.                                   '│
  186. END FUNCTION                      '└─────